/*
 * Copyright (c) 2016, www.zm0618.com All Rights Reserved..
 */

package com.ibetter.mr.parse.voteup;

import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by zhaojun on 2016/12/07.
 */
public class UserVoteMedicReducer extends Reducer<LongWritable,LongWritable,LongWritable,Text>{
    @Override
    protected void reduce(LongWritable key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
       if (values!=null){
           Iterator<LongWritable> iter = values.iterator();
           List<String> medicIdList=new ArrayList<String>();
           while (iter.hasNext()){
               LongWritable medicIdLong= iter.next();
               medicIdList.add(medicIdLong.toString());
           }
           context.write(key, new Text(StringUtils.join(medicIdList,",")));
       }
    }
}
